using System;
using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;

namespace ThridGroup.ERP.ProductionSystem
{
    /// <summary>
    /// 供应商测试数据种子
    /// </summary>
    public class SupplierDataSeedContributor : IDataSeedContributor, ITransientDependency
    {
        private readonly IRepository<SupplierModel, int> _supplierRepository;

        public SupplierDataSeedContributor(IRepository<SupplierModel, int> supplierRepository)
        {
            _supplierRepository = supplierRepository;
        }

        public async Task SeedAsync(DataSeedContext context)
        {
            // 检查是否已有供应商数据
            var existingCount = await _supplierRepository.CountAsync();
            if (existingCount > 0)
            {
                return; // 已有数据，不重复添加
            }

            // 添加测试供应商数据
            var suppliers = new[]
            {
                new SupplierModel
                {
                    SupplierCode = "V00002",
                    SupplierName = "北京昌平",
                    SupplierGrade = "正常",
                    SupplierScore = 0,
                    SupplierPhone = "",
                    IsEnable = true,
                    SupplierAdress = "",
                    Context = "",
                    IsDeleted = false
                },
                new SupplierModel
                {
                    SupplierCode = "V00004",
                    SupplierName = "GY1",
                    SupplierGrade = "正常",
                    SupplierScore = 0,
                    SupplierPhone = "",
                    IsEnable = true,
                    SupplierAdress = "",
                    Context = "",
                    IsDeleted = false
                },
                new SupplierModel
                {
                    SupplierCode = "V00005",
                    SupplierName = "启航钢丝",
                    SupplierGrade = "正常",
                    SupplierScore = 0,
                    SupplierPhone = "",
                    IsEnable = true,
                    SupplierAdress = "",
                    Context = "",
                    IsDeleted = false
                },
                new SupplierModel
                {
                    SupplierCode = "V00006",
                    SupplierName = "昂标外贸供应商",
                    SupplierGrade = "正常",
                    SupplierScore = 0,
                    SupplierPhone = "",
                    IsEnable = true,
                    SupplierAdress = "",
                    Context = "",
                    IsDeleted = false
                },
                new SupplierModel
                {
                    SupplierCode = "V00007",
                    SupplierName = "昂标模组供应商",
                    SupplierGrade = "正常",
                    SupplierScore = 0,
                    SupplierPhone = "",
                    IsEnable = true,
                    SupplierAdress = "",
                    Context = "",
                    IsDeleted = false
                },
                new SupplierModel
                {
                    SupplierCode = "V00008",
                    SupplierName = "昂标资供应商",
                    SupplierGrade = "正常",
                    SupplierScore = 0,
                    SupplierPhone = "",
                    IsEnable = true,
                    SupplierAdress = "",
                    Context = "",
                    IsDeleted = false
                },
                new SupplierModel
                {
                    SupplierCode = "test-测试001",
                    SupplierName = "test-测试",
                    SupplierGrade = "正常",
                    SupplierScore = 0,
                    SupplierPhone = "厦门供应商测试",
                    IsEnable = true,
                    SupplierAdress = "",
                    Context = "",
                    IsDeleted = false
                }
            };

            await _supplierRepository.InsertManyAsync(suppliers);
        }
    }
} 